<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Product extends Model
{
    protected $fillable=[
        'title',
        'description',
        'image',
        'price',
        'on_sale',
        'sold_count',
        'review_count',
        'rating',
        'price',
    ];
    protected $casts=['on_sale'=>'boolean'];
    public function skus(){
        return $this->hasMany(ProductSku::class);
    }
    public function getImageAttribute($value){
        if(strpos($value, 'http')===0)    // 必须使用3个等于号！
            return $value;
        return Storage::disk('admin')->url($value);
    }
}
